package deleteface.bank.jqsoft.cn.deleteface;

import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseViewHolder;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;


import java.util.ArrayList;
import java.util.List;

import cn.jqsoft.bank.deleteface.R;


public class DeleteForManyAdapter extends BaseQuickAdapterEx<String, BaseViewHolder> {

    private  Context context;
    public DeleteForManyAdapter(Context context,List<String> data) {
        super(R.layout.item_delete_layout, data);
        this.context=context;
    }


    @Override
    protected void convert(final BaseViewHolder helper, final String item) {

        final View finalCloseView = helper.getView(R.id.swipeView);// listView的itemView

        // 置顶按钮的单击事件

        helper.getView(R.id.btnTop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "置顶", Toast.LENGTH_SHORT).show();
                ((SwipeMenuLayout)(finalCloseView)).quickClose();// 关闭侧滑菜单：需要将itemView强转，然后调用quickClose()方法
            }
        });

        // 删除按钮的单击事件
        helper.getView(R.id.btnDelete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((SwipeMenuLayout)(finalCloseView)).quickClose();// 关闭侧滑菜单
                if (delItemListener != null){
                    delItemListener.delete(helper.getPosition());// 调用接口的方法，回调删除该项数据
                }
            }
        });



    }
    // 定义接口，包含了删除数据的方法
    interface DeleteItem{
        void delete(int pos);
    }

    private DeleteItem delItemListener;
    // 设置监听器的方法
    public void setDelItemListener(DeleteItem delItemListener){
        this.delItemListener = delItemListener;
    }



}
